package mr.flow.weblog.bean;

import org.apache.hadoop.io.WritableComparable;
import org.apache.hadoop.io.WritableComparator;

/**
 * 自定义的聚合规则
 * 相同的sessionId要进入同一个reduce进行处理
 * @author 汤小萌
 * @date 2018年11月28日 下午8:55:13
 */
public class SessionIdGroupingComparator extends WritableComparator {
	
	public SessionIdGroupingComparator() {
		super(PageViewsBean.class, true);
	}
	
	@Override
	public int compare(WritableComparable a, WritableComparable b) {
		PageViewsBean aBean = (PageViewsBean) a;
		PageViewsBean bBean = (PageViewsBean) b;
		// System.out.println(aBean.getSession()  + " -- " + bBean.getSession());
		// System.out.println(aBean.getSession().compareTo(bBean.getSession()));
		return aBean.getSession().compareTo(bBean.getSession());
	}
}
